package com.jiyun.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.model.xitong.Yaopin;
import com.jiyun.model.xitong.Zixun;
import com.jiyun.oss.AliyunOSSUtils;
import com.jiyun.service.IYaopinService;
import com.jiyun.service.IZixunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-24
 */
@RestController
@CrossOrigin
@RequestMapping("/yaopin")
@Api("药品管理")
public class YaopinController {
        @Autowired
        private IYaopinService yaopinService;


        @Autowired
        AliyunOSSUtils aliyunOSSUtils;

        @RequestMapping("findAll")
        @ApiOperation("分页查询所有药品")
        public Page<Yaopin> findAll(Integer pageNum, Integer pageSize, @RequestBody Yaopin yaopin){
                return  yaopinService.findAll(pageNum,pageSize,yaopin);
        }


        @RequestMapping("upload")
        @ApiOperation("上传图片")
        public String upload(MultipartFile file) throws IOException {
                String originalFilename = file.getOriginalFilename();
                InputStream inputStream = file.getInputStream();
                String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
                return s;
        }

        @RequestMapping("add")
        @ApiOperation("添加药品")
        public Integer add(@RequestBody Yaopin yaopin){
                return   yaopinService.add(yaopin);
        }

        @RequestMapping("update")
        @ApiOperation("修改药品信息")
        public Integer update(@RequestBody Yaopin yaopin){
                return  yaopinService.updates(yaopin);
        }

        @RequestMapping("del")
        @ApiOperation("删除药品")
        public Integer del(Integer id){
                return  yaopinService.del(id);
        }
}
